package com.jye.cloud.user.service.impl;

import com.jye.cloud.domain.Group;
import com.jye.cloud.domain.Options;
import com.jye.cloud.domain.Subject;
import com.jye.cloud.user.mapper.GroupMapper;
import com.jye.cloud.user.mapper.OptionsMapper;
import com.jye.cloud.user.mapper.SubjectMapper;
import com.jye.cloud.user.service.GroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GroupServiceImpl implements GroupService {

    @Autowired
    GroupMapper groupMapper;

    @Autowired
    OptionsMapper optionsMapper;

    @Autowired
    SubjectMapper subjectMapper;



    @Override
    public Group findGroupById(int id) {
        Group group = groupMapper.findGroupById(id);
        Integer total = 0;
        //题目
        List<Subject> subjectList = subjectMapper.findSubjectsByPId(group.getId());
        group.setSubjectList(subjectList);
        //选项
        for (Subject subject : subjectList) {
            total += subject.getGrade();
            List<Options> optionsList = optionsMapper.findOptionByPId(subject.getId());
            subject.setOptionsList(optionsList);
        }
        group.setTotal(total);
        return group;
    }

    @Override
    public List<Integer> findClassGroupByCId(int cId) {
        return groupMapper.findClassGroupByCId(cId);
    }

    @Override
    public String findTitleById(Integer id) {
        return groupMapper.findNameById(id);
    }
}
